﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisionRoc.Core;

namespace VisionRoc_Measure
{
    public partial class FormNineCalibrationtTool : Form
    {
        NineCalibrationt nineCalibrationt;
        public FormNineCalibrationtTool(NineCalibrationt _nineCalibrationt)
        {
            InitializeComponent();
            nineCalibrationt = _nineCalibrationt;
        }

        private void FormNineCalibrationtTool_Load(object sender, EventArgs e)
        {
            try
            {
                nineCalibrationt.ReadParameter();
                txt_ModelX.Text = nineCalibrationt.ModelX.ToString();
                txt_ModelY.Text = nineCalibrationt.ModelY.ToString();
                txt_ModelR.Text = nineCalibrationt.ModelR.ToString();
                txt_NineFilePath.Text = nineCalibrationt.NineCalibrationFilePath;
                if (nineCalibrationt.InIState == 1)
                {
                    tooldisplay.Text = "标定文件加载成功!";
                    tooldisplay.ForeColor = Color.Green;
                }
                else
                {
                    tooldisplay.Text = "标定文件加载失败!";
                    tooldisplay.ForeColor = Color.Red;
                }
            }
            catch (Exception ex)
            {
                txt_ModelX.Text = nineCalibrationt.ModelX.ToString();
                txt_ModelY.Text = nineCalibrationt.ModelY.ToString();
                txt_ModelR.Text = nineCalibrationt.ModelR.ToString();
                tooldisplay.Text = "标定文件加载失败!";
                tooldisplay.ForeColor = Color.Red;
                MessageBox.Show(ex.ToString());
            }
        }

        private void btn_select_ninefile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect = false;
                openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                openFileDialog.Filter = "九点标定文件XML|*.xml";
                openFileDialog.Title = "导入标定文件XML";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string filename = txt_NineFilePath.Text = openFileDialog.FileName;
                    nineCalibrationt.ReafCalibrationXML(openFileDialog.FileName);
                    //nineCalibrationt.HomMat2D = RotateCalculateAlgo.GenHomMat2D(nineCalibrationt.m_CalibrationData.SX, nineCalibrationt.m_CalibrationData.SY, nineCalibrationt.m_CalibrationData.Theta, nineCalibrationt.m_CalibrationData.Phi, nineCalibrationt.m_CalibrationData.TX, nineCalibrationt.m_CalibrationData.TY);
                    tooldisplay.Text = "九点标定文件XML加载成功!";
                    tooldisplay.ForeColor = Color.Green;
                }
            }
            catch (Exception ex)
            {
                tooldisplay.Text = "九点标定文件XML加载异常";
                tooldisplay.ForeColor = Color.Red;
                MessageBox.Show("九点标定文件XML加载异常 :" + ex.ToString());
            }
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                nineCalibrationt.ModelX = Convert.ToDouble(txt_ModelX.Text);
                nineCalibrationt.ModelY = Convert.ToDouble(txt_ModelY.Text);
                nineCalibrationt.ModelR = Convert.ToDouble(txt_ModelR.Text);
                nineCalibrationt.NineCalibrationFilePath = txt_NineFilePath.Text;
                nineCalibrationt.WriteParameter();
                MessageBox.Show("保存成功");
            }
            catch(Exception ex) 
            {
                MessageBox.Show(ex.ToString());
            }
         
        }
    }
}
